package com.design.classroommanagement.teacher

import com.alibaba.android.arouter.facade.annotation.Route
import com.design.classroommanagement.Pages
import com.design.classroommanagement.api.Bookmark
import com.design.classroommanagement.api.Classroom
import com.design.classroommanagement.api.dao.BookmarkDao
import com.design.classroommanagement.api.dao.ClassRoomDao
import com.design.classroommanagement.databinding.ActivityTeacherClassBinding
import com.laughing.lib.base.BaseFragmentNoVM
import com.laughing.lib.utils.clickWithTrigger
import com.laughing.lib.utils.runInBg
import com.laughing.lib.utils.saveGet


@Route(path = Pages.TeacherClassroomFragment)
class TeacherClassroomFragment : BaseFragmentNoVM<ActivityTeacherClassBinding>() {
    override fun initCompleted() {
        super.initCompleted()
        binding.apply {
            searchBtn.clickWithTrigger {
                runInBg {
                    val key = classnameEt.text.toString()
                    val classroom = ClassRoomDao.search(key).saveGet(0)
                    val bookmark = BookmarkDao.query { put("id", classroom?.bookmarkId ?: "") }.saveGet(0)
                    render(classroom, bookmark)
                }
            }
        }
    }

    private fun render(classroom: Classroom?, bookmark: Bookmark?) {
        binding.apply {
            courseNameTv.text = bookmark?.name
            countTv.text = ""
        }
    }
}